﻿using System;
using System.Drawing;
using System.Windows.Forms;

namespace 城市天然气管道风险管理与决策系统
{
    public partial class Form_menu_1_1 : Form
    {
        public Form_menu_1_1()
        {
            InitializeComponent();
        }

        private void Form_menu_1_1_Load(object sender, EventArgs e)
        {
            textBox1.ReadOnly = true;
            textBox2.ReadOnly = true;
            textBox3.ReadOnly = true;
            textBox4.ReadOnly = true;
            textBox5.ReadOnly = true;
            textBox6.ReadOnly = true;
            textBox7.ReadOnly = true;
            textBox8.ReadOnly = true;
            textBox9.ReadOnly = true;
            textBox10.ReadOnly = true;
            richTextBox1.ReadOnly = true;

            textBox1.Text = GlobalData.default_pipeline.Id.ToString();
            textBox2.Text = GlobalData.default_pipeline.Name;
            textBox4.Text = GlobalData.default_pipeline.StartLocation;
            textBox3.Text = GlobalData.default_pipeline.EndLocation;
            try
            {
                dateTimePicker1.Value = GlobalData.default_pipeline.InvestTime;
            }
            catch (Exception)
            {
                dateTimePicker1.Value = DateTime.Now;
            }
            textBox5.Text = GlobalData.default_pipeline.OperYear.ToString();
            textBox6.Text = GlobalData.default_pipeline.Pressure.ToString();
            textBox9.Text = GlobalData.default_pipeline.Ability.ToString();
            textBox7.Text = GlobalData.default_pipeline.Length.ToString();
            textBox8.Text = GlobalData.default_pipeline.Medium;
            textBox10.Text = GlobalData.default_pipeline.Unit;
            richTextBox1.Text = GlobalData.default_pipeline.Remark_Base;
        }

        private void skinButton1_Click(object sender, EventArgs e)
        {
            textBox10.ReadOnly = false;
            textBox5.ReadOnly = false;
            textBox6.ReadOnly = false;
            textBox7.ReadOnly = false;
            textBox8.ReadOnly = false;
            textBox9.ReadOnly = false;
            richTextBox1.ReadOnly = false;
        }

        private void skinButton3_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void skinButton4_Click(object sender, EventArgs e)
        {
            if (printDialog1.ShowDialog() == DialogResult.OK)
                printDocument1.Print();
        }

        private void skinButton2_Click(object sender, EventArgs e)
        {
            GlobalData.default_pipeline.InvestTime = dateTimePicker1.Value.Date;
            GlobalData.default_pipeline.OperYear = int.Parse(textBox5.Text);
            GlobalData.default_pipeline.Pressure = double.Parse(textBox6.Text);
            GlobalData.default_pipeline.Ability = double.Parse(textBox9.Text);
            GlobalData.default_pipeline.Length = double.Parse(textBox7.Text);
            GlobalData.default_pipeline.Medium = textBox8.Text;
            GlobalData.default_pipeline.Unit = textBox10.Text;
            GlobalData.default_pipeline.Remark_Base = richTextBox1.Text;

            textBox1.ReadOnly = true;
            textBox2.ReadOnly = true;
            textBox3.ReadOnly = true;
            textBox4.ReadOnly = true;
            textBox5.ReadOnly = true;
            textBox6.ReadOnly = true;
            textBox7.ReadOnly = true;
            textBox8.ReadOnly = true;
            textBox9.ReadOnly = true;
            textBox10.ReadOnly = true;
            richTextBox1.ReadOnly = true;
        }

        private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            string print_info = "";
            print_info += "管道ID：" + GlobalData.default_pipeline.Id.ToString();
            print_info += "\n管道名称：" + GlobalData.default_pipeline.Name;
            print_info += "\n起始位置：" + GlobalData.default_pipeline.StartLocation;
            print_info += "\n末端位置：" + GlobalData.default_pipeline.EndLocation;
            print_info += "\n投入时间：" + GlobalData.default_pipeline.InvestTime.ToString();
            print_info += "\n运行年限：" + GlobalData.default_pipeline.OperYear.ToString() + "年";
            print_info += "\n运行压力：" + GlobalData.default_pipeline.Pressure.ToString() + "MPa";
            print_info += "\n管道全长：" + GlobalData.default_pipeline.Length.ToString() + "Km";
            print_info += "\n输油能力：" + GlobalData.default_pipeline.Ability.ToString() + "t/年";
            print_info += "\n输油介质：" + GlobalData.default_pipeline.Medium;
            print_info += "\n所属单位：" + GlobalData.default_pipeline.Unit;
            print_info += "\n备注：" + GlobalData.default_pipeline.Remark_Base;

            printDialog1.ShowDialog();
            e.Graphics.DrawString(print_info, richTextBox1.Font, Brushes.Black, e.MarginBounds.X, e.MarginBounds.Y);
            printDocument1.DocumentName = GlobalData.default_pipeline.Name + "-管道信息";
        }
    }
}
